package edu.hm.devcamp.communication.json;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;

import edu.hm.devcamp.providers.Poi;

public class JsonParser {

    private static final ObjectMapper sMapper = new ObjectMapper();
    
    public static List<Poi> parseList(InputStream in) throws JsonParseException, JsonMappingException, IOException{
        
        JsonWrapper wrapper = sMapper.readValue(in, JsonWrapper.class);
        List<Poi> pois = wrapper.getPois();
                
        return pois;
    }
    
    public static Poi parse(InputStream in) throws JsonParseException, JsonMappingException, IOException{
        Poi poi = sMapper.readValue(in, Poi.class);
        
        return poi;
    }
    
    public static String parseToString(Poi poi) throws JsonGenerationException, JsonMappingException, IOException{
        String outString = sMapper.writeValueAsString(poi);
        
        return outString;
    }
}
